#!/bin/bash

# Configuration and Information Block
echo -e "Builder Environment Configuration:\n"

# Show installed software versions
java  --version
git   --version
node  --version
npm   --version

# Show Maven Configuration File
echo -e "\n--- Maven Settings.xml ---\n"
# The settings file is located in $MAVEN_HOME/conf/settings.xml
# MAVEN_HOME is set to /usr/share/maven in your Dockerfile.
if [ -f "$MAVEN_HOME/conf/settings.xml" ]; then
    cat "$MAVEN_HOME/conf/settings.xml"
else
    echo "ERROR: Maven settings file not found at $MAVEN_HOME/conf/settings.xml"
fi

# Show Maven Repository Path
echo -e "\n--- Maven Repository Path ---\n"
echo "Maven Local Repository: /repository/java"

# Show NPM Configuration
echo -e "\n--- NPM Configuration ---\n"
npm config set registry "https://registry.npmmirror.com"
npm config set prefix   "/repository/npm/global"
npm config set cache    "/repository/npm/cache"
# Verify NPM paths
npm config list | grep -E 'registry|prefix|cache'

# Main Execution Block
echo -e "\n-----------------------------\n"
echo -e "builder @mapway.cn\n\n"

# Prepare cache paths before changing directory
mkdir -p /repository/{java,npm/global,npm/cache,code}

cd /source

if [ -f ./autobuild.sh ]; then
   echo "Executing ./autobuild.sh..."
   bash ./autobuild.sh
else
   echo -e "ERROR: not found autobuild.sh in /source directory."
   exit 1
fi